package com.cmcc.passenger.ui.fragment

import android.app.Dialog
import android.os.Bundle
import android.view.LayoutInflater
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.DialogFragment
import com.cmcc.passenger.R
import com.cmcc.passenger.databinding.FragmentUserTermsBinding
import com.cmcc.shared.utils.clickWithTrigger


class UserTermsFragment : DialogFragment() {

    private lateinit var binding: FragmentUserTermsBinding

    private val testUrl = "https://www.acagrid.com/index/user/policy.html"

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        if (context == null || !isAdded) return super.onCreateDialog(savedInstanceState)
        val inflater = LayoutInflater.from(context)
        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_user_terms, null, false)
        val dialog = Dialog(context!!, R.style.TransparentStyleBottomDialog)
        dialog.setContentView(binding.root)

        val m = activity!!.windowManager
        val d = m.defaultDisplay
        val p = dialog.window!!.attributes
        p.width = (d.width * 0.9).toInt()
        dialog.window!!.attributes = p

        binding.userTerms.loadUrl(testUrl)
        binding.confirm.clickWithTrigger { dismiss() }
        return dialog
    }

    companion object {

        fun newFragment(): UserTermsFragment {
            return UserTermsFragment()
        }
    }


}
